home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / tlslite / Checker.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.3 KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Class for post-handshake certificate checking.'''
  5. from utils.cryptomath import hashAndBase64
  6. from X509 import X509
  7. from X509CertChain import X509CertChain
  8. from errors import *
  9.  
  10. class Checker:
  11.     """This class is passed to a handshake function to check the other
  12.     party's certificate chain.
  13.  
  14.     If a handshake function completes successfully, but the Checker
  15.     judges the other party's certificate chain to be missing or
  16.     inadequate, a subclass of
  17.     L{tlslite.errors.TLSAuthenticationError} will be raised.
  18.  
  19.     Currently, the Checker can check either an X.509 or a cryptoID
  20.     chain (for the latter, cryptoIDlib must be installed).
  21.     """
  22.     
  23.     def __init__(self, cryptoID = None, protocol = None, x509Fingerprint = None, x509TrustList = None, x509CommonName = None, checkResumedSession = False):
  24.         """Create a new Checker instance.
  25.  
  26.         You must pass in one of these argument combinations:
  27.          - cryptoID[, protocol] (requires cryptoIDlib)
  28.          - x509Fingerprint
  29.          - x509TrustList[, x509CommonName] (requires cryptlib_py)
  30.  
  31.         @type cryptoID: str
  32.         @param cryptoID: A cryptoID which the other party's certificate
  33.         chain must match.  The cryptoIDlib module must be installed.
  34.         Mutually exclusive with all of the 'x509...' arguments.
  35.  
  36.         @type protocol: str
  37.         @param protocol: A cryptoID protocol URI which the other
  38.         party's certificate chain must match.  Requires the 'cryptoID'
  39.         argument.
  40.  
  41.         @type x509Fingerprint: str
  42.         @param x509Fingerprint: A hex-encoded X.509 end-entity
  43.         fingerprint which the other party's end-entity certificate must
  44.         match.  Mutually exclusive with the 'cryptoID' and
  45.         'x509TrustList' arguments.
  46.  
  47.         @type x509TrustList: list of L{tlslite.X509.X509}
  48.         @param x509TrustList: A list of trusted root certificates.  The
  49.         other party must present a certificate chain which extends to
  50.         one of these root certificates.  The cryptlib_py module must be
  51.         installed.  Mutually exclusive with the 'cryptoID' and
  52.         'x509Fingerprint' arguments.
  53.  
  54.         @type x509CommonName: str
  55.         @param x509CommonName: The end-entity certificate's 'CN' field
  56.         must match this value.  For a web server, this is typically a
  57.         server name such as 'www.amazon.com'.  Mutually exclusive with
  58.         the 'cryptoID' and 'x509Fingerprint' arguments.  Requires the
  59.         'x509TrustList' argument.
  60.  
  61.         @type checkResumedSession: bool
  62.         @param checkResumedSession: If resumed sessions should be
  63.         checked.  This defaults to False, on the theory that if the
  64.         session was checked once, we don't need to bother
  65.         re-checking it.
  66.         """
  67.         if cryptoID:
  68.             if x509Fingerprint or x509TrustList:
  69.                 raise ValueError()
  70.         x509TrustList
  71.         if x509Fingerprint and x509TrustList:
  72.             raise ValueError()
  73.         x509TrustList
  74.         if x509CommonName and not x509TrustList:
  75.             raise ValueError()
  76.         not x509TrustList
  77.         if protocol and not cryptoID:
  78.             raise ValueError()
  79.         not cryptoID
  80.         if cryptoID:
  81.             import cryptoIDlib
  82.         
  83.         if x509TrustList:
  84.             import cryptlib_py
  85.         
  86.         self.cryptoID = cryptoID
  87.         self.protocol = protocol
  88.         self.x509Fingerprint = x509Fingerprint
  89.         self.x509TrustList = x509TrustList
  90.         self.x509CommonName = x509CommonName
  91.         self.checkResumedSession = checkResumedSession
  92.  
  93.     
  94.     def __call__(self, connection):
  95.         """Check a TLSConnection.
  96.  
  97.         When a Checker is passed to a handshake function, this will
  98.         be called at the end of the function.
  99.  
  100.         @type connection: L{tlslite.TLSConnection.TLSConnection}
  101.         @param connection: The TLSConnection to examine.
  102.  
  103.         @raise tlslite.errors.TLSAuthenticationError: If the other
  104.         party's certificate chain is missing or bad.
  105.         """
  106.         if not (self.checkResumedSession) and connection.resumed:
  107.             return None
  108.  
  109.  
  110.